using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;

using PHSRAG.Insight21.Policy;
using PHSRAG.Insight21.CDS;
using PHSRAG.Utility;


namespace InsightWebService
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {
            PHSRAG.Insight21.Policy.ICachePolicy cachePolicy = null;

            if (Application[PHSRAG.Insight21.Policy.Names.ApplicationCachePolicyKey] == null)
            {
                string assemblyName = Settings.GetKeyValue("ApplicationCachePolicyProvider.Assembly", null);
                string className = Settings.GetKeyValue("ApplicationCachePolicyProvider.Class", null);

                cachePolicy = (PHSRAG.Insight21.Policy.ICachePolicy)InstanceCreator.Create(assemblyName, className, Application);
                if (cachePolicy == null)
                    cachePolicy = new PHSRAG.Insight21.Policy.NullCachePolicy();
                Application[PHSRAG.Insight21.Policy.Names.ApplicationCachePolicyKey] = cachePolicy;
            }

            //Load RefCodes data
            if (cachePolicy.GetCachedObject(PHSRAG.Insight21.CDS.RefCodes.CacheKey) == null)
            {
                PHSRAG.Insight21.CDS.RefCodes refCodes = new PHSRAG.Insight21.CDS.RefCodes(cachePolicy);
                refCodes.Load(DataAccess.ConnectionString, null);
                cachePolicy.Cache(PHSRAG.Insight21.CDS.RefCodes.CacheKey, refCodes);
            }

        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}